package com.wangp.mywrite.s_netty.chat_group.server.handler;

import com.wangp.mywrite.s_netty.chat_group.server.session.SessionFactory;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

/**
 * @author tooStronger
 * @date 2023/4/22
 */
@Slf4j
public class QuitHandler extends ChannelInboundHandlerAdapter {


    // 链接断开触发
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        SessionFactory.getSession().unbind(ctx.channel());
        log.info("{} 已断开", ctx.channel());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        SessionFactory.getSession().unbind(ctx.channel());
        log.info("{} 已异常断开 ， {} ", ctx.channel(), cause.getMessage());
    }
}
